﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProDivingJudge2salmon14
{
    public class FormMainPresenter
    {
        IFormMain viewFormMain;
        INewJudgeForm viewNewJudgeForm;

        IClientConnection modelClientConnection;
        IDataManager modelDataManager;

        public FormMainPresenter(IFormMain viewFormMain, INewJudgeForm viewNewJudgeForm, ClientConnection modelClientConnection, DataManager modelDataManager)
        {
            this.viewFormMain = viewFormMain;
            this.viewNewJudgeForm = viewNewJudgeForm;

            this.modelClientConnection = modelClientConnection;
            this.modelDataManager = modelDataManager;

            this.viewFormMain.EventConnectToServer += ConnectToServer;
            this.viewFormMain.EventGetIsConnected += GetIsConnected;
            this.viewFormMain.EventSend += Send;
            this.viewFormMain.EventGetDiveCode += GetDiveCode;
            this.viewFormMain.EventGetJudgeName += GetJudgeName;
            this.viewFormMain.EventGetJudgeID += GetJudgeID;
            this.viewFormMain.EventSetJudgeName += SetJudgeName;
            this.viewFormMain.EventGetJudgeLayout += GetJudgeLayout;
            this.viewFormMain.EventSetEmptyDiveCode += SetEmptyDiveCode;
            this.viewFormMain.EventGetIsReceivedNewData += GetIsReceivedNewData;
            this.viewFormMain.EventSetIsReceivedNewData += SetIsReceivedNewData;
            this.viewFormMain.EventGetDiveOrder += GetDiveOrder;

            this.viewNewJudgeForm.EventSetJudgeID += SetJudgeID;
            this.viewNewJudgeForm.EventSetJudgeLayout += SetJudgeLayout;
            this.viewNewJudgeForm.EventSetServerIP += SetServerIP;
            this.viewNewJudgeForm.EventSetServerPort += SetServerPort;
        }

        private string GetDiveOrder()
        {
            return this.modelDataManager.GetDiveOrder();
        }

        private void SetIsReceivedNewData(bool isReceivedNewData)
        {
            this.modelDataManager.SetIsReceivedNewData(isReceivedNewData);
        }

        private bool GetIsReceivedNewData()
        {
            return this.modelDataManager.GetIsReceivedNewData();
        }

        private void SetEmptyDiveCode()
        {
            this.modelDataManager.SetEmptyDiveCode();
        }

        private string GetJudgeLayout()
        {
            return this.modelDataManager.GetJudgeLayout();
        }

        private int GetJudgeID()
        {
            return this.modelDataManager.GetJudgeID();
        }

        private string GetJudgeName()
        {
            return this.modelDataManager.GetJudgeName();
        }

        private string GetDiveCode()
        {
            return this.modelDataManager.GetDiveCode();
        }

        private void ConnectToServer()
        {
            this.modelClientConnection.ConnectToServer();
        }

        private bool GetIsConnected()
        {
            return this.modelClientConnection.GetIsConnected();
        }

        private void Send(string text)
        {
            this.modelClientConnection.Send(text);
        }

        private void SetJudgeID(int judgeID)
        {
            this.modelDataManager.SetJudgeID(judgeID);
        }

        private void SetJudgeLayout(string judgeLayout)
        {
            this.modelDataManager.SetJudgeLayout(judgeLayout);
        }

        private void SetJudgeName(string judgeName)
        {
            this.modelDataManager.SetJudgeName(judgeName);
        }

        private void SetServerIP(string serverIP)
        {
            this.modelClientConnection.SetServerIP(serverIP);
        }

        private void SetServerPort(int serverPort)
        {
            this.modelClientConnection.SetServerPort(serverPort);
        }
    }
}
